import fs from 'fs'
import { exec } from 'child_process'
import ora from 'ora'

const spinner = ora('下载中...')

export const hasFile = (name) => {
    return fs.existsSync(name)
}

export const downloadGit = (url, name) => {
    return new Promise((resolve, reject) => {
        spinner.start()
        exec(`git clone ${url} ${name}`, (err, stdout, stderr) => {
            if (err) {
                spinner.fail()
                reject(err)
            } else {
                spinner.succeed()
                resolve(stdout)
            }
        }
        )
    })
}